/**
 * 
 */
package br.srv.full.virtual.entities.persons;

import java.util.List;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

import br.srv.full.virtual.entities.auth.User;
import br.srv.full.virtual.entities.ids.FederalId;
import br.srv.full.virtual.entities.ids.StateId;

/**
 * @author Delfino
 * 
 */
@Entity
@Table(name = "clients")
@DiscriminatorValue(value = "C")
@Inheritance(strategy = InheritanceType.JOINED)
@PrimaryKeyJoinColumn(name = "clientid", referencedColumnName = "userid")
public class Client extends User {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@ManyToOne(optional = true, targetEntity = Retailer.class, fetch = FetchType.EAGER)
	@JoinColumn(name = "authorizedretailerid", referencedColumnName = "retailerid", nullable = false)
	private Retailer retailer;

	@OneToMany(fetch = FetchType.LAZY, targetEntity = Worker.class, mappedBy = "client")
	private List<Worker> workers;

	@Embedded
	@AttributeOverrides( { @AttributeOverride(name = "type", column = @Column(name = "federalIdType")),
			@AttributeOverride(name = "number", column = @Column(name = "federalIdNumber")) })
	private FederalId federalId;

	@Embedded
	@AttributeOverrides( { @AttributeOverride(name = "type", column = @Column(name = "stateIdType")),
			@AttributeOverride(name = "number", column = @Column(name = "stateIdNumber")),
			@AttributeOverride(name = "emiter", column = @Column(name = "stateIdEmiter")) })
	private StateId stateId;

	/**
	 * @return the retailer
	 */
	public Retailer getRetailer() {
		return retailer;
	}

	/**
	 * @param p_retailer
	 *            the retailer to set
	 */
	public void setRetailer(Retailer p_retailer) {
		retailer = p_retailer;
	}

	/**
	 * @return the workers
	 */
	public List<Worker> getWorkers() {
		return workers;
	}

	/**
	 * @param p_workers
	 *            the workers to set
	 */
	public void setWorkers(List<Worker> p_workers) {
		workers = p_workers;
	}

	/**
	 * @return the federalId
	 */
	public FederalId getFederalId() {
		return federalId;
	}

	/**
	 * @param p_federalId
	 *            the federalId to set
	 */
	public void setFederalId(FederalId p_federalId) {
		federalId = p_federalId;
	}

	/**
	 * @return the stateId
	 */
	public StateId getStateId() {
		return stateId;
	}

	/**
	 * @param p_stateId
	 *            the stateId to set
	 */
	public void setStateId(StateId p_stateId) {
		stateId = p_stateId;
	}
}
